package com.holystone.orca.sys.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.holystone.orca.base.service.impl.BaseServiceImpl;
import com.holystone.orca.sys.model.StaffVO;
import com.holystone.orca.sys.mybatis.dao.SysStaffMapper;
import com.holystone.orca.sys.mybatis.model.SysStaff;
import com.holystone.orca.sys.service.ISysDepartmentService;
import com.holystone.orca.sys.service.ISysStaffService;
@Service("StaffService")
public class SysStaffServiceImpl extends BaseServiceImpl<SysStaff> implements ISysStaffService{

	@Autowired
	private SysStaffMapper sysStaffMapper;
	@Autowired
	private ISysDepartmentService sysDepartmentService;

	@Override
	public boolean insertStaffByPersonId(Map<Object, String> map) throws Exception{
		int result=sysStaffMapper.insertStaffByPersonId(map);
		if(result==1){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public boolean updateStaffByPersonId(Map<Object,String> map) throws Exception {
		int result=sysStaffMapper.updateStaffByPersonId(map);
		if(result==1){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public int selectDepIdByPersonId(int personId) throws Exception{
		int result = sysStaffMapper.selectdepId(personId);
		return result;
	}

	@Override
	public boolean deleteStaffByPersonId(int personId) {
		int result=sysStaffMapper.deleteStaffByPersonId(personId);
		if(result==1){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public boolean delSelectStaff(List<Integer> list) throws Exception {
		int result=sysStaffMapper.delSelectStaff(list);
		if(result==list.size()){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public List<StaffVO> selectBelowDepStaff(Integer depId,int staffId) throws Exception {
		List<Integer> list = sysDepartmentService.selectDepChildrenIdsById(depId, "");
		list.remove(depId);
		if(list.size()==0){
			return new ArrayList<StaffVO>();
		}
		List<StaffVO> listss = sysStaffMapper.getStaffVOByDepIds(list,staffId);
		return listss;
	}

    @Override
    public List<Integer> selectDepIdsByPersonId(String userId) {
        Integer id = userId == null ? 0 : Integer.parseInt(userId);
        return sysStaffMapper.selectDepIdByPersonId(id);
    }
}
